package com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.swing.plaf.SpinnerUI;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller
public class DateController {


    //基本类型参数获取
    @RequestMapping("arg1")
    @ResponseBody
    public void arg1(@RequestParam(value = "name",defaultValue = "wangwu") String name,@RequestParam(value = "age",defaultValue = "20") int age){
        System.out.println(name);
        System.out.println(age);
    }

    //类类型参数的获取
    @RequestMapping("arg2")
    @ResponseBody
    public void arg2(User user){
        System.out.println(user);
    }

    //获取请求json格式的数据
    //底层是使用jackson进行json解析后存入
    @RequestMapping("/arg3")
    @ResponseBody
    public void arg3(@RequestBody User user){
        System.out.println(user);
    }

    //数组类型参数获取
    //获取形式为在url输入数组名=内容的形式在控制台输出数组形式内容
    @RequestMapping("/arg4")
    @ResponseBody
    public void arg4(String[] list){
        System.out.println(Arrays.toString(list));
    }

    //集合类型参数获取
    @RequestMapping("/arg5")
    @ResponseBody
    public void arg5(@RequestBody List<User> list){
        System.out.println(list);
    }

    //请求类型转换器
    //请求时在url中输入参数=内容的形式来写
    //需要自定义一个实现转换器接口的类，用于确定字符串的格式，以便于让spring判断并转换成date格式
    //然后最重要不要忘记springxml文件中的内容要修改
    @RequestMapping("/arg6")
    @ResponseBody
    public void arg6(Date date){
        System.out.println(date);
    }

    //请求头信息的获取
    @RequestMapping("/arg7")
    @ResponseBody
    public void save7(@RequestHeader(value = "sec-ch-ua-platform",required = false) String user_agent) throws IOException {
        System.out.println(user_agent);
    }


    @RequestMapping(value="/arg9")
    @ResponseBody
    public void addCookie(Cookie cookie){
        cookie.setValue("fhfv");
    }

    //请求头cookie数据获取
    @RequestMapping(value="/arg8")
    @ResponseBody
    public void arg8(@CookieValue(value = "JSESSIONID") String jsessionId) throws IOException {
        System.out.println(jsessionId);
    }

}
